package pikes.html.xhtml.list;

import java.util.LinkedList;

import pikes.html.xhtml.Block;
import pikes.html.xhtml.CoreAttributes;
import pikes.html.xhtml.Events;
import pikes.html.xhtml.I18N;
import pikes.html.xhtml.NonRootTagFactory;
import pikes.xml.XMLTag;
import pikes.util.Assert;

/**
 * <code>&lt;dl/&gt;</code> tag, see <a href="http://www.w3.org/TR/html401/struct/lists.html#h-10.3">dl element</a>
 * in HTML specification.
 * @author Peter Bona
 * @see <a href="http://www.w3.org/TR/html401/struct/lists.html#h-10.3">The dl element in HTML specification</a>
 */
public class DefinitionList extends NonRootTagFactory implements Block, CoreAttributes, I18N, Events {

	private java.util.List<DefinitionItem> items = new LinkedList<DefinitionItem>();

	final protected CharSequence getTagName() {
		return "dl";
	}

	public DefinitionList(Term term, Description description) {
		Assert.notNull(term);
		Assert.notNull(description);
		items.add(term);
		items.add(description);
	}

	public void addTerm(Term term) {
		if (term != null) {
			items.add(term);
		}
	}

	public void addDescription(Description description) {
		if (description != null) {
			items.add(description);
		}
	}

	public void add(Term term, Description description) {
		addTerm(term);
		addDescription(description);
	}

	@Override
	protected void decorateCreatedTag(XMLTag tag) {
		for (DefinitionItem item : items) {
			item.decorateTag(tag);
		}
	}

}
